package com.ruoyi.project.outpatient.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.outpatient.domain.Register;
import com.ruoyi.project.outpatient.domain.RegisterType;
import com.ruoyi.project.outpatient.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 挂号列表
 */
@RestController
@RequestMapping("/outpatient/register")
public class RegisterController extends BaseController {

    @Autowired
    private RegisterService registerService;

    //查询挂号信息
    @PreAuthorize("@ss.hasAnyPermi('outpatient:register:list')")
    @GetMapping("/list2")
    public TableDataInfo findRegisterInfo(Register register){
        startPage();
        List<Register> list = registerService.selectRegisterInfo(register);

        return getDataTable(list);
    }

    /**
     * 获取挂号类型选择框列表
     */
    @GetMapping("/list3")
    public AjaxResult findRegisterType()
    {
        List<RegisterType> registerTypes = registerService.selectRegisterType();
        return AjaxResult.success(registerTypes);
    }

    @PreAuthorize("@ss.hasPermi('outpatient:register:add')")
    @Log(title = "新增挂号信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addRegister(@Validated @RequestBody Register register)
    {
        register.setCreateBy(SecurityUtils.getUsername());
        return toAjax(registerService.insertRegister(register));
    }

    @PreAuthorize("@ss.hasAnyPermi('outpatient:list:list')")
    @GetMapping("/list7")
    public TableDataInfo findRegiDeInfo(Register register){
        startPage();
        List<Register> list = registerService.selectRegiDeInfo(register);
        return getDataTable(list);
    }

    /**
     * 根据角色编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('outpatient:list:list')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult selectReCostInfo(@PathVariable String registerId)
    {
        return AjaxResult.success(registerService.selectReCostInfo(registerId));
    }

    @PreAuthorize("@ss.hasPermi('outpatient:list:list')")
    @Log(title = "修改挂号收费信息", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult updateReCostInfo(@Validated @RequestBody Register register)
    {

        register.setCreateBy(SecurityUtils.getUsername());
        return toAjax(registerService.updateReCostInfo(register));
    }
}
